package edu.dayu.config;

import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @author by dayu
 * @date 2023/4/11.
 */
@Component
public class EnvironmentTest implements EnvironmentAware {
    // environment 可以获得很多种环境的东西
    private Environment environment;

    @Override
    public void setEnvironment(Environment environment) {
        this.environment = environment;
    }

    // postConstruct 是 java 的注解，相当于 spring 的 init-method 当 bean 完成实例化前，执行初始化方法。
    @PostConstruct
    public void post(){
        System.out.println(environment.getProperty("spring.application.name"));
    }
}
